<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>自己的电商系统</title>
	<base href="http://localhost/shop/" />
	<link rel="stylesheet" type="text/css" href="/tpshop/Public/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="/tpshop/Public/css/bootstrap-theme.min.css">
	<link rel="stylesheet" type="text/css" href="/tpshop/Public/css/style.css">
</head>
<body class="container">
	<div class="row">
		<div class="col-md-3">
			<a href="/tpshop"><img id="logo" src="/tpshop/Public/img/logo.png" /></a>
		</div>
		<div class="col-md-9">
			<img style="height:50px;" class="pull-right" src="public/img/shop_step_2.jpg" />	
		</div>
	</div>
	<br />
	<div class="row">
		<div class="col-md-12">
			<form action="" method="POST">
			<table class="table-bordered">
				<h3>收货地址<button id="tianjia" class="btn-xs btn-success pull-right" >添加收获地址</button></h3>
				<?php foreach ($address as $a) {?>
				<tr>
					<td width="40px"><input type="radio" name="address_id" value="<?=$a['id'] ?>"></td>
					<td width="100px;">姓名:<?=$a['name'] ?></td>   
					<td width="200px;"><?= $a['address'] ?></td>
					<td width="350px;"><?= $a['phone'] ?></td>
					<td width="330px;"><a href="">修改</a><a>删除</a></td>
				</tr>
				<?php }?>
			</table>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">
			<table class="table table-bordered">
				<tr>
					<th>商品</th>
					<th width="150">价格</th>
					<th width="150">数量</th>
					<th width="120">小计</th>
				</tr>
				<?php
 $sum = 0; foreach($data as $c){ $product = M('product')->where('id ='.$c['product_id'])->find(); ?>
				<tr class='t'>
					<input type="hidden" name="product_id[]" value="<?=$c['product_id'] ?>">
					<input type="hidden" name="num[]" value="<?=$c['num'] ?>">
					<td><img style="width:60px;" src="/tpshop<?=$product['img']?>"><a href="<?=U('Home/product/detail/id/'.$product['id'])?>"><?=$product['title']?></a></td>
					<td>￥<?=$product['price']?></td>
					<td class="cart_num">
					<?=$c['num']?>
					</td>
					<td>￥<?php echo $p = intval($product['price']) * intval($c['num'])?></td>
					<?php $sum = $sum +$p;?>
				</tr>
				<?php }?>
			</table>
			<button id="checkout" type="submit" href="#" class="btn btn-danger pull-right">提交订单</button>
			</form>
		</div>
	</div>
	<div id="addressform" class="modal fade">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<form id="addressform">
					<div class="form-group">
						<label for="exampleInputEmail1">收件人</label>
						<input type="text" name="name" class="form-control" id="exampleInputEmail1" placeholder="请输入收件人姓名">
					</div>
					<div class="form-group">
						<label for="exampleInputEmail1">地址</label>
						<textarea name="address" style="width:300px;height:200px;"  class="address" id="exampleInputEmail1" placeholder="请输入地址"></textarea>
					</div>
					<div class="form-group">
						<label for="exampleInputEmail1">电话</label>
						<input name="phone" type="text" name="phone" class="form-control" id="exampleInputEmail1" placeholder="请输入电话">
					</div>
					</form>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="addAddress">保存</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript" src=" /tpshop/Public/js/jquery-3.1.0.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#tianjia').click(function(){
				$('#addressform').modal('show');
			})
			$('#addAddress').click(function(){
				var name= $('#addressform input[name="name"]').val();
				var address= $('#addressform textarea[name="address"]').val();
				var phone= $('#addressform input[name="phone"]').val();
				$.post("<?= U('Home/Shopping/addAddress')?>",{'name':name,'address':address,'phone':phone},
				function(data){
					if (data=="ok") {
						location.reload();
					}else{
						alert(data);
					}
				})
				return false;
			})
		});
	</script>
</body>
</html>